package com.tablepet.activities.main;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ItemTouchHelper;

import com.tablepet.R;
import com.tablepet.adapter.ShowcaseAdapter;
import com.tablepet.bean.ShowcaseBean;
import com.tablepet.databinding.FragmentShowcaseBinding;
import com.tablepet.utils.swipe.CardConfig;
import com.tablepet.utils.swipe.SwipeCardCallback;
import com.tablepet.utils.swipe.SwipeCardLayoutManager;

import java.util.ArrayList;
import java.util.List;
public class ShowcaseFragment extends Fragment {
    private FragmentShowcaseBinding binding;
    private final List<ShowcaseBean> data=new ArrayList<>();
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentShowcaseBinding.inflate(inflater, container, false);
        CardConfig.initConfig(requireActivity());
        binding.showcaseRecycleview.setLayoutManager(new SwipeCardLayoutManager());
        binding.showcaseRecycleview.setAdapter(new ShowcaseAdapter(requireContext(),data));
        new ItemTouchHelper(new SwipeCardCallback(binding.showcaseRecycleview, binding.showcaseRecycleview.getAdapter(), data)).attachToRecyclerView(binding.showcaseRecycleview);
        data.clear();
        data.add(new ShowcaseBean( R.drawable.a,"1"));
        data.add(new ShowcaseBean( R.drawable.b,"2"));
        data.add(new ShowcaseBean( R.drawable.c,"3"));
        data.add(new ShowcaseBean( R.drawable.d,"4"));
        data.add(new ShowcaseBean( R.drawable.e,"5"));
        data.add(new ShowcaseBean( R.drawable.f,"6"));
        data.add(new ShowcaseBean( R.drawable.g,"7"));
        data.add(new ShowcaseBean( R.drawable.h,"8"));
        binding.showcaseRecycleview.getAdapter().notifyDataSetChanged();
        return binding.getRoot();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}